package cn.yzw.jc.sandbox.spring;

import cn.yzw.jc.sandbox.spring.monitor.SpringBeanStartMonitor;
import com.alibaba.jvm.sandbox.api.Information;
import com.alibaba.jvm.sandbox.api.Module;
import com.alibaba.jvm.sandbox.api.ModuleLifecycle;
import com.alibaba.jvm.sandbox.api.resource.ModuleEventWatcher;
import org.kohsuke.MetaInfServices;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Resource;

/**
 * SpringBoot 启动耗时统计-agent
 * @author liucan@yzw.cn write on 2024/1/8 15:08
 */
@MetaInfServices(Module.class)
@Information(id = "SpringInitializeBeanModule", mode = {Information.Mode.AGENT}, version = "1.0.0", author = "liucan@yzw.cn")
public class SpringInitializeBeanModule implements Module, ModuleLifecycle {
    private final static Logger log = LoggerFactory.getLogger(SpringInitializeBeanModule.class);
    @Resource
    private ModuleEventWatcher moduleEventWatcher;

    @Override
    public void onLoad() throws Throwable {
        // 模块加载
        log.info("SpringStartModule onLoad..");
    }

    @Override
    public void onUnload() throws Throwable {
        // 模块卸载
        log.info("SpringStartModule onUnload..");
    }

    @Override
    public void onActive() throws Throwable {
        // 模块激活
        log.info("SpringStartModule onActive..");
    }

    @Override
    public void onFrozen() throws Throwable {
        // 模块冻结
        log.info("SpringStartModule onFrozen..");
    }

    @Override
    public void loadCompleted() {
        // 模块记载完成
        log.info("SpringStartModule loadCompleted..");
        new SpringBeanStartMonitor(moduleEventWatcher).start();
    }
}
